# 发送钉钉卡片消息

from dingtalkchatbot.chatbot import DingtalkChatbot, CardItem, ActionCard


# 发送卡片1
def send_card1():
    url = 'https://oapi.dingtalk.com/robot/send?access_token=fe16d4a6014b41ecc47ea25ab2ad7f70ef96cbb26010b15'
    bot = DingtalkChatbot(url, secret='SEC29d0b538722d74b84807d8d387c851035d9a98fc99841e')

    card1 = CardItem(title='百度搜索~', url='http://www.baidu.com',
                     pic_url='https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png')
    card2 = CardItem(title='360 搜索~', url='https://hao.360.com/',
                     pic_url='https://hao2.qhimg.com/t01b27bb76e133d0ee1.png')
    card3 = CardItem(title='Bing 搜索~', url='https://cn.bing.com/',
                     pic_url='https://tse4-mm.cn.bing.net/th/id/OIP-C.lC2hkoOBxXR-Ln6N3O6-3gHaC_?pid=ImgDet&rs=1')
    cards = [card1, card2, card3]
    bot.send_feed_card(cards)


# 发送卡片2
def send_card2():
    url = 'https://oapi.dingtalk.com/robot/send?access_token=fe4c685ecc47ea25ab2ad7f70ef96cbb26010b15'
    bot = DingtalkChatbot(url, secret='SEC29d0b538722d74b84804d8d387c851035d9a98fc99841e')

    # Link消息
    # ActionCard整体跳转消息类型
    btns1 = [CardItem(title="查看详情", url="https://www.itbaizhan.cn/")]
    actioncard1 = ActionCard(title='万万没想到,竟然...',
                             text='![选择](https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png)',
                             btns=btns1,
                             btn_orientation=1,
                             hide_avatar=1)

    bot.send_action_card(actioncard1)


# 发送卡片3
def send_card3():
    url = 'https://oapi.dingtalk.com/robot/send?access_token=fe16d4a601c049870b914ef96cbb26010b15'
    bot = DingtalkChatbot(url, secret='SEC29d0b53872387c851035d9a98fc99841e')

    # Link消息
    # ActionCard整体跳转消息类型
    btns1 = [CardItem(title="支持", url="https://www.itbaizhan.cn/"),CardItem(title="反对", url="http://www.baidu.com")]
    actioncard1 = ActionCard(title='万万没想到,竟然...',
                             text='![选择](https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png)',
                             btns=btns1,
                             btn_orientation=1,
                             hide_avatar=1)

    bot.send_action_card(actioncard1)


if __name__ == '__main__':
    # send_card1()
    # send_card2()
    send_card3()
